/******************************************************************************\
*                                                                              *
*     File: Trace.h                                                            *
*                                                                              *
*   Author: Douwe A. van Twillert                                              *
*  Purpose: To ease tracing for debugging purposes                             *
*  Version: 1.0      TWI 20070309                                              *
*           - Initial version                                                  *
*  Version: 1.0.2    TWI 20070323                                              *
*           - Changed all tabs to spaces                                       *
*           - Made versioning comments consistent                              *
*  Version: 1.1      TWI 20080218                                              *
*           - Changed the header file for clear printing                       *
*                                                                              *
\******************************************************************************/

#ifndef TRACE_H
#define TRACE_H

//#include <assert.h>
#include <iostream>
#include <signal.h>

/*
 * Een C++ manier om met een klasse functies mee te kunnen tracen
 */
class Tracer {
    const char* the_filename;
    int the_linenr;
    const char* the_function;

public:
    Tracer( const char* a_filename, int a_linenr, const char* a_function ) :
         the_filename( a_filename ) , the_linenr( a_linenr ),
         the_function( a_function )
    {
        std::cout << ">>> \"" << the_filename << "\"[" << the_linenr << "] "
                  << the_function << std::endl << std::flush;
    }

    ~Tracer()
    {
        std::cout << "<<< \"" << the_filename << "\"[" << the_linenr << "] "
                  << the_function << std::endl << std::flush;
    }
};

#ifdef TRACING
    #define TRACE(s) std::cout << "<" << __FILE__ << ">[" <<  __LINE__ << "] " \
                               << s << std::endl << std::flush ;
    #define TRACE_FUNC Tracer __ftrace( __FILE__, __LINE__, __PRETTY_FUNC__ );
#else
    #define TRACE(s) ((void)0);
    #define TRACE_FUNC ((void)0);
#endif  // TRACING

#endif // TRACE_H
